package main

import "fmt"

//Definition for singly-linked list.
type ListNode struct {
	Val  int
	Next *ListNode
}

func deleteDuplicates(head *ListNode) *ListNode {
	if head == nil || head.Next == nil {
		return head
	}

	var r *ListNode = head
	var tmp *ListNode = head.Next
	for {
		if tmp == nil {
			break
		}
		if tmp.Val == r.Val {
			r.Next = tmp.Next
			tmp = tmp.Next
			continue
		}
		r = r.Next
	}
	return head
}

func main() {
	var head *ListNode = &ListNode{}
	t := head
	s := []int{1, 2, 3, 3, 4, 4, 5}
	for _, v := range s {
		t.Next = &ListNode{
			Val:  v,
			Next: nil,
		}
		t = t.Next
	}
	head = head.Next
	r := deleteDuplicates(head)
	for {
		if r == nil {
			break
		}
		fmt.Println(r.Val)
		r = r.Next
	}

}
